package cn.lang.service;

import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONObject;
import cn.lang.manager.HolidayApiManager;
import cn.lang.manager.MailManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author Lang 1102076808@qq.com
 * @description
 * @date 2020-10-30 22:16
 */
@Service
public class HolidayService {

	@Autowired
	private HolidayApiManager holidayApiManager;

	@Autowired
	private MailManager mailManager;
	/**
	 * @description
	 * @author Lang
	 * @date 2020/10/30 23:17
	 */
	 public void holidayApp(){

		 Date now = new Date();
		 Date offsetDay = DateUtil.offsetDay(now, 2);

		 /* 今天是否是法定节假日 */
		 JSONObject holidayInfo = holidayApiManager.getHolidayInfo(now);
		 JSONObject type = holidayInfo.getJSONObject("type");
		 if(type.getInt("type")==2){
			 mailManager.sendMail("今天",type.getStr("name"));
		 }

		 /* 后天是否是节假日 */
		 JSONObject holidayInfo2 = holidayApiManager.getHolidayInfo(offsetDay);
		 JSONObject type2 = holidayInfo2.getJSONObject("type");
		 if(type2.getInt("type")==2){
			 mailManager.sendMail("后天",type2.getStr("name"));
		 }

		 /* 今天是否是纪念日 */
		 JSONObject jsonObject = holidayApiManager.loveDay(now);
		 if(jsonObject.getInt("code")==1){
			 mailManager.sendMail("今天",jsonObject.getStr("name"));
		 }

		 /* 后天是否是纪念日 */
		 JSONObject jsonObject2 = holidayApiManager.loveDay(offsetDay);
		 if(jsonObject2.getInt("code")==1){
			 mailManager.sendMail("后天",jsonObject2.getStr("name"));
		 }
	 }

}
